package lab03;

import java.sql.*;

public class Test12 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");//注册驱动程序
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        //第二阶段编码，connection,statement,resultset
        Connection connection = null;
        Statement statement = null;

        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                    "root","113223" );//三个参数
            statement = connection.createStatement();
            //查询所有记录
            ResultSet resultSet = statement.executeQuery("SELECT *FROM t_user ");
            //	查询用户名为'admin'的记录
            resultSet = statement.executeQuery("SELECT * FROM t_user WHERE usename = 'admin'");
            //3)	查询用户名为'admin'，密码为'123456'的记录
            resultSet = statement.executeQuery("SELECT * FROM  t_user WHERE username ='admin'and" +
                    " password = 123456");
            //4)	查询注册时间大于10000000的记录
            resultSet = statement.executeQuery("SELECT * FROM t_user WHERE register_datetime >10000000");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            connection.close();
            statement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
